package com.yyh.synctool.server.service.impl;

import com.yyh.pojo.SyncParam;
import com.yyh.result.JsonResult;
import com.yyh.synctool.server.service.ProviderService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author xuan
 * @date 2021/12/17
 */
@Service
public class ProviderServiceImpl implements ProviderService
{
    private RabbitTemplate rabbitTemplate;

    @Autowired
    public ProviderServiceImpl(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    @Override
    public JsonResult syncStock(SyncParam<List<Map>> syncParam) {

        List<Map> data = syncParam.getData();
        data.forEach(e -> {
            e.put("GSID", syncParam.getGsid());
        });
        rabbitTemplate.convertAndSend("stock", data);

        return JsonResult.getSuccess("成功");
    }

    @Override
    public JsonResult syncPrice(SyncParam syncParam) {
        return JsonResult.getSuccess("成功");
    }

}
